package com.leet.code.simple_array;

/**
 * @description:
 * @author: WYG
 * @time: 2020/11/29 11:40
 */

public class IsMonotonic {

    public boolean isMonotonic(int[] A) {
        int length = A.length;
        if (length < 3) {
            return true;
        }
        boolean a = true;
        boolean b = true;
        for (int i = 0; i < length - 1; i++) {
            if (A[i] > A[i + 1]) {
                a = false;
            }
        }
        for (int i = 0; i < length - 1; i++) {
            if (A[i] < A[i + 1]) {
                b = false;
            }
        }
        return a || b;
    }
    public boolean Monotonic(int[] A) {
        int k = 0;
        int j = 0;
        for (int i = 0; i < A.length - 1; i++) {
            if (A[i] > A[i + 1]) {
                k++;
            } else if (A[i] < A[i + 1]){
                j++;
            }
            if (k!=0&&j!=0) {
                return false;
            }
        }
        return k * j == 0;
    }
}
